package com.stevenmoon.csdnplus.logic;

import com.google.gson.reflect.TypeToken;
import com.stevenmoon.csdnplus.app.Constants.CSDNURL;
import com.stevenmoon.csdnplus.bean.ResponseResultBean;
import com.stevenmoon.csdnplus.bean.blog.BlogCateTagInfo;
import com.stevenmoon.csdnplus.bean.blog.BlogCateTopTagInfo;
import com.stevenmoon.csdnplus.bean.blog.BlogCategoryArticleListReqBean;
import com.stevenmoon.csdnplus.bean.blog.BlogCategoryInfo;
import com.stevenmoon.csdnplus.bean.blog.BlogCategoryListReqBean;
import com.stevenmoon.csdnplus.bean.blog.BlogColumnInfo;
import com.stevenmoon.csdnplus.bean.blog.BlogColumnListReqBean;
import com.stevenmoon.csdnplus.bean.blog.BlogCommentAddInfo;
import com.stevenmoon.csdnplus.bean.blog.BlogCommentAddReqBean;
import com.stevenmoon.csdnplus.bean.blog.BlogCommentInfo;
import com.stevenmoon.csdnplus.bean.blog.BlogCommentsReqBean;
import com.stevenmoon.csdnplus.bean.blog.BlogDetailInfo;
import com.stevenmoon.csdnplus.bean.blog.BlogExpertInfo;
import com.stevenmoon.csdnplus.bean.blog.BlogNormalListInfo;
import com.stevenmoon.csdnplus.bean.blog.BlogNormalListReqBean;
import com.stevenmoon.csdnplus.bean.blog.BlogOperationInfo;
import com.stevenmoon.csdnplus.bean.blog.BlogOperationReqBean;
import com.stevenmoon.csdnplus.bean.blog.BlogRecentPostInfo;
import com.stevenmoon.csdnplus.bean.blog.BlogRecommendListInfo;
import com.stevenmoon.csdnplus.bean.blog.BlogRecommendListReqBean;
import com.stevenmoon.csdnplus.bean.blog.BlogTagInfo;
import com.stevenmoon.csdnplus.bean.blog.BlogUserArticleListReqBean;
import com.stevenmoon.csdnplus.net.RequestParams;
import com.stevenmoon.csdnplus.net.RxNet;
import com.stevenmoon.csdnplus.util.CollectionUtil;
import com.stevenmoon.csdnplus.util.GsonUtil;

import java.util.List;

import rx.Observable;

/**
 * Created by WangJun on 2016/5/7.
 */
public class BlogManager {

    public static Observable<List<BlogRecommendListInfo>> getRecommendBlogList(BlogRecommendListReqBean reqBean){
        RequestParams rp = new RequestParams(CSDNURL.BLOG_RECOMMAND_LIST, GsonUtil.convertBean2Map(reqBean));
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<List<BlogRecommendListInfo>>>(){});
    }

    public static Observable<List<BlogNormalListInfo>> getNormalBlogList(BlogNormalListReqBean reqBean){
        RequestParams rp = new RequestParams(CSDNURL.BLOG_SUBSCRIBE_LIST, GsonUtil.convertBean2Map(reqBean));
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<List<BlogNormalListInfo>>>(){});
    }

    public static Observable<List<BlogNormalListInfo>> getUserBlogList(BlogUserArticleListReqBean reqBean){
        RequestParams rp = new RequestParams(CSDNURL.BLOG_USER_ARTICLE_LIST, GsonUtil.convertBean2Map(reqBean));
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<List<BlogNormalListInfo>>>(){});
    }

    public static Observable<List<BlogTagInfo>> getSubscribeBlogTags(){
        RequestParams rp = new RequestParams(CSDNURL.BLOG_SUBSCRIBE_TAGS);
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<List<BlogTagInfo>>>(){});
    }

    public static Observable<BlogDetailInfo> getBlogDetail(int articleId, String username){
        RequestParams rp = new RequestParams(CSDNURL.BLOG_DETAIL);
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<BlogDetailInfo>>(){});
    }

    public static Observable<List<BlogCommentInfo>> getBlogComments(BlogCommentsReqBean reqBean){
        RequestParams rp = new RequestParams(CSDNURL.BLOG_COMMENT_LIST, GsonUtil.convertBean2Map(reqBean));
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<List<BlogCommentInfo>>>(){});
    }

    public static Observable<BlogOperationInfo> doBlogUpOrDown(BlogOperationReqBean reqBean){
        RequestParams rp = new RequestParams(CSDNURL.BLOG_UP_DOWN);
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<BlogOperationInfo>>(){});
    }

    public static Observable<BlogCommentAddInfo> doBlogUpOrDown(BlogCommentAddReqBean reqBean){
        RequestParams rp = new RequestParams(CSDNURL.BLOG_COMMENT_ADD);
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<BlogCommentAddInfo>>(){});
    }

    public static Observable<List<BlogExpertInfo>> getMyFocusExperts(){
        RequestParams rp = new RequestParams(CSDNURL.BLOG_FOCUS_EXPERTS);
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<List<BlogExpertInfo>>>(){});
    }

    public static Observable<List<BlogRecentPostInfo>> getRecentPosts(List<String> usernames){
        RequestParams rp = new RequestParams(CSDNURL.BLOG_POST_RECENTLY);
        rp.put("usernames", CollectionUtil.convertParamList2String(usernames));
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<List<BlogRecentPostInfo>>>(){});
    }

    public static Observable<BlogExpertInfo> getExpertInfo(int expertId){
        RequestParams rp = new RequestParams(CSDNURL.BLOG_EXPERT_INFO);
        rp.put("expertId", expertId);
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<BlogExpertInfo>>(){});
    }

    public static Observable<List<BlogNormalListInfo>> getUserCateArticleList(BlogCategoryArticleListReqBean reqBean){
        RequestParams rp = new RequestParams(CSDNURL.BLOG_ARTICLE_LIST, GsonUtil.convertBean2Map(reqBean));
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<List<BlogNormalListInfo>>>(){});
    }

    public static Observable<List<BlogCategoryInfo>> getUserCategoryList(BlogCategoryListReqBean reqBean){
        RequestParams rp = new RequestParams(CSDNURL.BLOG_CATEGORY_LIST, GsonUtil.convertBean2Map(reqBean));
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<List<BlogCategoryInfo>>>(){});
    }

    public static Observable<List<BlogColumnInfo>> getUserColumnList(BlogColumnListReqBean reqBean){
        RequestParams rp = new RequestParams(CSDNURL.BLOG_COLUMN_LIST, GsonUtil.convertBean2Map(reqBean));
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<List<BlogColumnInfo>>>(){});
    }

    public static Observable<BlogColumnInfo> getUserColumnDetail(String alias){
        RequestParams rp = new RequestParams(CSDNURL.BLOG_COLUMN_DETAIL);
        rp.put("alias", alias);
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<BlogColumnInfo>>(){});
    }

    public static Observable<List<BlogNormalListInfo>> getUserColumnArticleList(BlogColumnListReqBean reqBean){
        RequestParams rp = new RequestParams(CSDNURL.BLOG_COLUMN_ARTICLE_LIST, GsonUtil.convertBean2Map(reqBean));
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<List<BlogNormalListInfo>>>(){});
    }

    /**
     * 获取获取博客分类一级标签
     * @return
     */
    public static Observable<List<BlogCateTopTagInfo>> getCateTopTags(){
        RequestParams rp = new RequestParams(CSDNURL.BLOG_CATE_TOP_TAGS);
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<List<BlogCateTopTagInfo>>>(){});
    }

    /**
     * 获取获取博客分类多级标签
     * @return
     */
    public static Observable<List<BlogCateTagInfo>> getCateAllTags(){
        RequestParams rp = new RequestParams(CSDNURL.BLOG_CATE_ALL_TAGS);
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<List<BlogCateTagInfo>>>(){});
    }

    public static Observable<String> editSubscribeTags(List<Integer> addIds, List<Integer> delIds){
        RequestParams rp = new RequestParams(CSDNURL.BLOG_SUBSCRIBE_TAGS_EDIT);
        rp.put("addIds", CollectionUtil.convertParamList2String(addIds));
        rp.put("delIds", CollectionUtil.convertParamList2String(delIds));
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<String>>(){});
    }

    public static Observable<List<BlogExpertInfo>> getExpertList(int channelId){
        RequestParams rp = new RequestParams(CSDNURL.BLOG_EXPERT_LIST);
        rp.put("channelId", channelId);
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<List<BlogExpertInfo>>>(){});
    }


}
